<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 *
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 *
 * @package      Feather's website
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://feather.portalier.com
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

abstract class TagsController extends Controller
{
	protected $restrictedAccess = array('administer', 'rename', 'erase');
	public    $_templates = 'simple_tags';
	
	public $refererClass;
	
	abstract function beforeAction();
	
	function cloud()
	{
		$this->data = $this->{$this->modelClass}->getCloud();
	}
	
	// admin
	
	function administer()
	{
		$model = $this->{$this->modelClass};
		
		if (isset($this->params['url'][$model->tagName]))
			$model->conditions(array($model->tagName => "LIKE {$this->params['url']['tag']}%"));
		
		$this->data = $model->listField($model->tagName, -1);
	}
	
	function rename()
	{
		if (!empty($data))
		{
			$data =& $this->data[$this->modelClass];
			if ($this->{$this->modelClass}->rename($data['old'], $data['new']))
				$this->flash(_('The tag has been renamed.'), 'administer');
			else
				$this->Session->setFlash(_('Oops, an error occured.'));
		}
	}
	
	function erase($tag)
	{
		if ($this->{$this->modelClass}->delete())
			$this->flash(_('The tag has been erased.'), getReferer());
		else
			$this->flash(_('Oops, an error occured.'), getReferer());
	}
}
?>